home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / misc.swg / 0202_Various Useful Routines.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-08-30  |  38.7 KB  |  1,650 lines

  1.  
  2. { Unit for Common Interface Routines }
  3.  
  4. Unit ETC;
  5. {$O+}
  6.  
  7. (************) interface (*************)
  8.  
  9. type carriertype = function:boolean;
  10.  
  11.  var
  12.     ANSI       : Boolean;
  13.     useinsert  : boolean;
  14.     CapsOn     : Boolean;
  15.     PortCheck  : Boolean;
  16.     carrierfunc: carriertype;
  17.  
  18.  
  19.  
  20.  
  21. Type pwtype = array[1..3] of word;
  22.  
  23. type dofiletype = function(fn:string):boolean;
  24.  
  25. attribtype = 1..24;
  26. attribset = set of attribtype;    { access attribute set A-X }
  27.  
  28. function trimch(s:string;c:char):string;
  29.  
  30. function sizeoffilespec(s:string):longint;
  31.  
  32. procedure CopyFile(s,d:string);
  33.  
  34. function Rows:byte;
  35. function columns:byte;
  36.  
  37. procedure ungetch(key:word);
  38.  
  39. function xpos(sub:char;main:string;x:byte):byte;
  40. function StripSpaces(s:string):string;
  41.  
  42. procedure printscreen;
  43. function AttribStr(a:attribset):string;
  44.  
  45. function rjustify(s:string;l:byte):string;
  46.  
  47. {Function HexStr(n:longint):string;}
  48.  
  49. Procedure KillFileSpec(p:string);
  50.  
  51. function Byte2Hex(numb : byte): string;       { Converts byte to hex string }
  52. function Word2Hex(numb: word): string;        { Converts word to hex string.}
  53. function Long2Hex(L: longint): string;     { Converts longint to hex string }
  54.  
  55. function base36(n:longint):string;
  56. function SplitFilePath(s:string):string;
  57. function SplitFileExt (s:string):string;
  58. function SplitFileName(s:string):string;
  59. procedure Longhash(s:string;var r:pwtype);
  60.  
  61. function  numtowords(n:word):string;
  62. procedure prunedir(p:string);
  63. function  DtTmStamp: string;
  64.  
  65. function  tostr2(s:longint;b:byte):string;
  66.  
  67. procedure movefile(fp:string;td:string);
  68. function  ToStr(s: longint): string;
  69.  
  70. function  tostrb(var s:byte):string;
  71. function  CurTimestr: string;
  72. procedure PR(t: string);
  73. procedure Newline;
  74. procedure ColorFG(c: byte);
  75. procedure ColorBG(c: byte);
  76. procedure PhoneEditor(var AnswerForMain: string; prestring: string;fgc,bgc:byte);
  77. procedure Editor(maxlen: byte; var Answerformain: string; prestring: string;fgc,bgc:byte);
  78. procedure Setup_Output;
  79. procedure ShowMC(Ch: char);
  80. procedure GetChoice(numofchoices: byte; Choices: string;fgc,bgc,oc:byte; var Reply: byte);
  81. procedure ClearScreen;
  82. function  Key: char;
  83. function  lowcase(ch: char): char;
  84. function  casestr(s: string): string;
  85. function  Ltab(n: integer;m:integer):string;
  86. function  Ltabc(n,m:integer;c:char):string;
  87.  
  88. function  UpcaseStr(s:string):String;
  89. function  lowcasestr(s:string):string;
  90.  
  91. function  ExistFile(s: string;flags:word): Boolean;
  92.  
  93. function  compare(s1,s2:string):byte;
  94. Procedure CursorOff;
  95. Procedure CursorOn;
  96. function  Rtrim(s:string):string;
  97. function  ltrim(s:string):string;
  98. procedure beep(Hz,Ms:word);
  99. {function  carrier_on:boolean;}
  100. procedure CurTime(var h:word; var m: word;var s:word);
  101. function  SecondsSinceMidnight(h,m,s:word):longint;
  102. function  nowsecondssincemidnight: longint;
  103. function ShortPath(s:string):string;
  104.  
  105. function nowmins: word;
  106.  
  107. function toint(s:string):word;
  108.  
  109. function tolong(s:string):longint;
  110.  
  111. function CRC32Array(p:pointer;l:longint):longint;
  112.  
  113. FUNCTION UpdCrc(cp: BYTE; crc: WORD): WORD;
  114. FUNCTION UpdC32(octet: BYTE; crc: LONGINT) : LONGINT;
  115.  
  116. function DVLoaded:boolean;
  117.  
  118. function Hex2Byte(s:string):byte;
  119.  
  120.  
  121. function int2comma(l:longint;b:byte):string;
  122.  
  123. Procedure wordCrypt(P: pointer;l:word;progcode:string);
  124.  
  125. procedure throughfiles(filespec:string;df:dofiletype);
  126.  
  127. function FindStrInarRay(var buf;l:word;fs:string):word;
  128.  
  129. Function Power(b,e:longint):longint;
  130.  
  131. function C2Pas(var s):string;
  132.  
  133. function nthoc(c:char;b:byte;s:string):byte;
  134.  
  135. procedure SetFlag(i:word;var a);
  136.  
  137. function readflag(i:word;var a):boolean;
  138.  
  139. function barepasswdinput(m:byte): string;
  140.  
  141.  
  142. (************) Implementation (***************)
  143.  
  144. uses crt,dos;
  145.  
  146.  
  147. function barepasswdinput(m:byte): string;
  148.   var s:string;
  149.       c:char;
  150.   begin
  151.   s:='';
  152.  
  153.   repeat
  154.     begin
  155.     repeat
  156.       if portcheck then
  157.         if not carrierfunc then
  158.          begin
  159.          Exit;
  160.          end
  161.     until keypressed;
  162.     c:=readkey;
  163.     case c of
  164.       #8: if length(s)>0 then
  165.             begin
  166.             write(#8+' '+#8);
  167.             dec(byte(s[0]));
  168.             end;
  169.  
  170.       ' '..'~': if length(s)<m then
  171.                   begin
  172.                   s:=s+c;
  173.                   write('.');
  174.                   end;
  175.       end
  176.     end
  177.   until c=#13;
  178.   barepasswdinput:=s;
  179.   end;
  180.  
  181.  
  182. procedure SetFlag(i:word;var a);
  183.  var temp: byte;
  184. begin { i is bit to be set }
  185. i:=i-1; { 1st bit is offset 0 }
  186. temp := i DIV (1 * 8);
  187. mem[seg(a):ofs(a)+temp] := mem[seg(a):ofs(a)+temp] OR Power(2,i);
  188. end;
  189.  
  190.  
  191. function readflag(i:word;var a):boolean;
  192.  var temp: byte;
  193. begin { i is bit to be set }
  194. i:=i-1; { 1st bit is offset 0 }
  195. temp := i DIV (1 * 8);
  196. readflag := (mem[seg(a):ofs(a)+temp]) AND Power(2,i) = power(2,i);
  197. end;
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204. function nthoc(c:char;b:byte;s:string):byte;
  205.  var i:byte;
  206.      cnt:byte;
  207.  begin
  208.  cnt:=0;
  209.  for i:=1 to length(s) do
  210.    begin
  211.    if s[i]=c then inc(cnt);
  212.    if cnt=b then
  213.      begin
  214.      nthoc:=i;
  215.      exit;
  216.      end;
  217.    end;
  218.  end;
  219.  
  220. procedure CopyFile(s,d:string);
  221.  const bs=16384;
  222.  type bt=array[1..bs] of byte;
  223.  var sf,df:file;
  224.      b:^bt;
  225.      i:word;
  226.      fs:longint;
  227.  
  228.  begin
  229.  new(b);
  230.  assign(sf,s);
  231.  reset(sf,1);
  232.  assign(df,d);
  233.  rewrite(df,1);
  234.  
  235.  fs:=filesize(sf);
  236.  
  237.  for i:=1 to (fs div bs) do
  238.    begin
  239.    blockread(sf,b^,bs);
  240.    blockwrite(df,b^,bs);
  241.    end;
  242.  
  243.  blockread(sf,b^,fs mod bs);
  244.  blockwrite(df,b^,fs mod bs);
  245.  
  246.  dispose(b);
  247.  
  248.  close(sf);
  249.  close(df);
  250.  
  251.  end;
  252.  
  253.  
  254. function c2pas(var s):string;
  255. var b :^String;
  256.  begin
  257.  b:= ptr(seg(s),ofs(s)-1);
  258.  b^[0]:=#255;
  259.  b^[0]:=char(pos(#0,b^));
  260.  c2pas:=b^;
  261.  end;
  262.  
  263.  Function Power(b,e:longint):longint;
  264.    var t,c:longint;
  265.    begin
  266.    t:=b;
  267.    if e=0 then begin power:=1 ; exit end;
  268.    for c:=1 to e-1 do t:=t*b;
  269.    power:=t;
  270.    end;
  271.  
  272. function FindStrInarRay(var buf;l:word;fs:string):word;
  273.  type bigbuft = array[1..65535] of char;
  274.  var buffer: bigbuft absolute buf;
  275.      p:word;
  276.      sscrc:longint;
  277.  
  278.  procedure loop;
  279.   var c:word;
  280.       ts:string;
  281.   begin
  282.  
  283.   ts[0]:=fs[0];
  284.  
  285.   for c:=1 to l-length(fs) do
  286.     begin
  287.     move(buffer[c],ts[1],length(fs));
  288.     if ts=fs then
  289.      begin
  290.      p:=c;
  291.      exit;
  292.      end;
  293.  
  294.     {if sscrc=crc32array(@buffer[c],length(fs)) then
  295.       begin
  296.       p:=c;
  297.       exit;
  298.       end;
  299.     }
  300.  
  301.  
  302.  
  303.  
  304.     end;
  305.   end;
  306.  
  307.  
  308.  begin
  309.  
  310.  if l<length(fs) then
  311.   begin
  312.   findstrinarray:=$ffff;
  313.   exit;
  314.   end;
  315.  
  316. { sscrc:=Crc32Array(@fs[1],length(fs));}
  317.  
  318.  p:=$FFFF;
  319.  
  320.  loop;
  321.  
  322.  FindStrInArray:=p;
  323.  end;
  324.  
  325.  
  326. procedure throughfiles(filespec:string;df:dofiletype);
  327.  var s:searchrec;
  328.      p:string;
  329.  
  330.  begin
  331.  p:=splitfilepath(filespec);
  332.  
  333.  FindFirst(FileSpec,AnyFile XOR Directory XOR SysFile XOR ReadOnly,S);
  334.  
  335.  while DosError=0 do
  336.    begin
  337.    if not df(p+s.name) then exit;
  338.    findnext(S)
  339.    end
  340.  
  341.  end;
  342.  
  343.  
  344. function sizeoffilespec(s:string):longint;
  345.   var sr:searchrec;
  346.        t:longint;
  347.   begin
  348.   t:=0;
  349.  
  350.   FindFirst(s,AnyFile,sr);
  351.   while DosError=0 do
  352.    begin
  353.    if sr.name[1]<>'.' then inc(t,sr.size);
  354.  
  355.    findnext(Sr)
  356.    end;
  357.  
  358.   sizeoffilespec:=t;
  359.   end;
  360.  
  361. function rows:byte;
  362.  type BiosType = Array[0..$A1] of byte;
  363.  var Bios: BiosType absolute $40:0;
  364.  begin
  365.  Rows := Bios[$84] + 1;
  366.  end;
  367.  
  368. function columns:byte;
  369.  type BiosType = Array[0..$A1] of byte;
  370.  var Bios: BiosType absolute $40:0;
  371.  begin
  372.  columns := Bios[$4A];
  373.  end;
  374.  
  375.  
  376. {procedure ungetch(c:char);
  377.  begin
  378.   memw[$40:$1a]:=$1e;
  379.   memw[$40:$1c]:=$1e+2;
  380.   memw[$40:$1c+2]:=ord(c);
  381.  end;}
  382.  
  383. {procedure ungetch(c:char);
  384.  var nread: word absolute $40:$1a;
  385.      npush: word absolute $40:$1c;
  386.  begin
  387.   if (npush-nread)<30 then
  388.     begin
  389.     memw[$40:npush]:=ord(c);
  390.     inc(npush,2);
  391.     end
  392.  end;}
  393.  
  394. PROCEDURE ungetch( Key : WORD ); ASSEMBLER;
  395. asm
  396.   mov ah, $05
  397.   mov cx, Key
  398.   int $16
  399. End;
  400.  
  401. Procedure wordCrypt(P: pointer;l:word;progcode:string);
  402.  var i:word;
  403.  begin
  404.  for i:=0 to l-1 do
  405.   begin
  406.   mem[seg(p^):ofs(p^)+i]:=mem[seg(p^):ofs(p^)+i] xor Byte(ProgCode[i mod ord (ProgCode [0])+1])
  407.   end;
  408.  end;
  409.  
  410. function trimch(s:string;c:char):string;
  411.  begin
  412.  trimch:=ltrim(copy(s,pos(c,s)+1,length(s)-pos(c,s)));
  413.  end;
  414.  
  415. function StripSpaces(s:string):string;
  416. var a:byte;
  417.  begin
  418.  a:=pos(' ',s);
  419.  while a<>0 do begin
  420.    delete(s,a,1);
  421.    a:=pos(' ',s) end;
  422.  StripSpaces:=s;
  423.  end;
  424.  
  425. function xpos(sub:char;main:string;x:byte):byte;
  426.  var i:byte;
  427.      n:byte;
  428.      p:byte;
  429.  begin
  430.  n:=0;
  431.  for i:=1 to x do
  432.    begin
  433.    p:=pos(sub,main);
  434.    if p=0 then
  435.      begin
  436.      xpos:=0;
  437.      exit;
  438.      end
  439.    else
  440.     begin
  441.     delete(main,1,p);
  442.     n:=p;
  443.     end;
  444.    end;
  445.  xpos:=n;
  446.  end;
  447.  
  448. function Byte2Hex(numb : byte): string;       { Converts byte to hex string }
  449.   const
  450.     HexChars : array[0..15] of char = '0123456789ABCDEF';
  451.   begin
  452.     Byte2Hex[0] := #2;
  453.     Byte2Hex[1] := HexChars[numb shr  4];
  454.     Byte2Hex[2] := HexChars[numb and 15];
  455.   end; { Byte2Hex }
  456.  
  457. function Word2Hex(numb: word): string;        { Converts word to hex string.}
  458.   begin
  459.     Word2Hex := Byte2Hex(hi(numb))+Byte2Hex(lo(numb));
  460.   end; { Numb2Hex }
  461.  
  462. function Long2Hex(L: longint): string;     { Converts longint to hex string }
  463.   begin
  464.     Long2Hex :=Word2Hex(L shr 16)+ Word2Hex(word(L)) ;
  465.   end; { Long2Hex }
  466.  
  467. Function AttribStr(a:attribset):string;
  468.  var i:word;
  469.      s:string;
  470.  begin
  471.  s[0]:=chr(0);
  472.  for i:=1 to 24 do
  473.    if i in a then
  474.      begin
  475.      s[0]:=chr(ord(s[0])+1);
  476.      s[i]:=chr(64+i);
  477.      end;
  478.  
  479. { for i:=1 to ord(s[0]) do
  480.    begin
  481.  
  482.  
  483.  
  484.    end;}
  485.  attribstr:=s;
  486.  
  487.  end;
  488.  
  489. function rjustify(s:string;l:byte):string;
  490.  var i:byte;
  491.      a:string;
  492.  
  493.  begin
  494.  a:=s;
  495.  while length(a)<l do insert(' ',a,1);
  496.  rjustify:=a;
  497.  end;
  498.  
  499.  
  500. procedure movefile(fp:string;td:string);
  501.  var f:file;
  502.  
  503.  begin
  504.  assign(f,fp);
  505.  rename(f,td+'\'+SplitFileName(fp));
  506.  
  507.  end;
  508.  
  509.  
  510. function int2comma(l:longint;b:byte):string;
  511.  var s:string;
  512.      i:integer;
  513.  begin
  514.  
  515.  str(l:b,s);
  516.  
  517.  i:=length(s)-2;
  518.  while i>1 do
  519.    begin
  520.  
  521.    if s[i-1]<> ' ' then insert(',',s,i) else insert(' ',s,i);
  522.  
  523.    dec(i,3);
  524.    end;
  525.  int2comma:=s;
  526.  end;
  527.  
  528. function DVloaded:boolean;
  529. var in_dv:boolean;
  530. begin
  531. in_dv:=false;
  532.   asm
  533.     mov cx,'DE'
  534.     mov dx,'SQ'
  535.     mov ax,$2b01
  536.     int $21
  537.     cmp al,$ff
  538.     je @No_Desqview
  539.     mov In_DV,true
  540.     @No_Desqview:
  541.   end;
  542. dvloaded:= in_dv;
  543. end;
  544.  
  545. function Hex2Byte(s:string):byte;
  546. const val: array[0..15] of char = '0123456789ABCDEF';
  547. var i:byte;
  548.     t:byte;
  549.   begin
  550.   if length(s)=1 then s:='0'+s;
  551.   s:=upcasestr(copy(s,1,2));
  552.   for i:=0 to 15 do if s[1]=val[i] then t:=i*$10;
  553.   for i:=0 to 15 do if s[2]=val[i] then inc(t,i);
  554.   Hex2Byte:=t;
  555.   end;
  556.  
  557. function base36(n:longint):string;
  558. var t:string;
  559.     i:byte;
  560.  
  561.  const d36:array[0..35] of char =' 123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  562.  begin
  563.   
  564.   t:=d36[    n div (36*36*36*36*36)]+
  565.      d36[   (n mod (36*36*36*36*36)) div (36*36*36*36)]+
  566.      d36[  ((n mod (36*36*36*36*36)) mod (36*36*36*36)) div (36*36*36)]+
  567.      d36[ (((n mod (36*36*36*36*36)) mod (36*36*36*36)) mod (36*36*36)) div (36*36)]+
  568.      d36[((((n mod (36*36*36*36*36)) mod (36*36*36*36)) mod (36*36*36)) mod (36*36)) div 36]+
  569.      d36[((((n mod (36*36*36*36*36)) mod (36*36*36*36)) mod (36*36*36)) mod (36*36)) mod 36];
  570.  
  571.   t:=ltrim(t);
  572.   for i:=1 to length(t) do if t[i]=' ' then t[i]:='0';
  573.   base36:=t;
  574.   end;
  575.  
  576. Function HexStr(n:longint):string;
  577. var t:string;
  578.     i:byte;
  579.  
  580.  const d16:array[0..15] of char =' 123456789ABCDEF';
  581.  begin
  582.   t:=d16[      n div $1000000]+
  583.      d16[     (n mod $1000000) div $100000]+
  584.      d16[    ((n mod $1000000) mod $100000) div $10000]+
  585.      d16[   (((n mod $1000000) mod $100000) mod $10000) div $1000]+
  586.      d16[  ((((n mod $1000000) mod $100000) mod $10000) mod $1000) div $100]+
  587.      d16[ (((((n mod $1000000) mod $100000) mod $10000) mod $1000) mod $100) div $10]+
  588.      d16[ (((((n mod $1000000) mod $100000) mod $10000) mod $1000) mod $100) mod $10];
  589.  
  590.   t:=ltrim(t);
  591.   for i:=1 to length(t) do if t[i]=' ' then t[i]:='0';
  592.   hexstr:=t;
  593.   end;
  594.  
  595.  
  596. function CRC32Array(p:pointer;l:longint):longint;
  597.  var i   :longint;crc :longint;
  598.  begin
  599.  CRC:=$FfFfFfFf;
  600.  for i:= 1 to l do CRC:=UpDC32(mem[seg(p^):ofs(p^)+i-1],crc);
  601.  CRC32ARRAY:=crc;
  602.  end;
  603.  
  604.  
  605. (* crctab calculated by Mark G. Mendel, Network Systems Corporation *)
  606. CONST crctab: ARRAY[0..255] OF WORD = (
  607.     $0000,  $1021,  $2042,  $3063,  $4084,  $50a5,  $60c6,  $70e7,
  608.     $8108,  $9129,  $a14a,  $b16b,  $c18c,  $d1ad,  $e1ce,  $f1ef,
  609.     $1231,  $0210,  $3273,  $2252,  $52b5,  $4294,  $72f7,  $62d6,
  610.     $9339,  $8318,  $b37b,  $a35a,  $d3bd,  $c39c,  $f3ff,  $e3de,
  611.     $2462,  $3443,  $0420,  $1401,  $64e6,  $74c7,  $44a4,  $5485,
  612.     $a56a,  $b54b,  $8528,  $9509,  $e5ee,  $f5cf,  $c5ac,  $d58d,
  613.     $3653,  $2672,  $1611,  $0630,  $76d7,  $66f6,  $5695,  $46b4,
  614.     $b75b,  $a77a,  $9719,  $8738,  $f7df,  $e7fe,  $d79d,  $c7bc,
  615.     $48c4,  $58e5,  $6886,  $78a7,  $0840,  $1861,  $2802,  $3823,
  616.     $c9cc,  $d9ed,  $e98e,  $f9af,  $8948,  $9969,  $a90a,  $b92b,
  617.     $5af5,  $4ad4,  $7ab7,  $6a96,  $1a71,  $0a50,  $3a33,  $2a12,
  618.     $dbfd,  $cbdc,  $fbbf,  $eb9e,  $9b79,  $8b58,  $bb3b,  $ab1a,
  619.     $6ca6,  $7c87,  $4ce4,  $5cc5,  $2c22,  $3c03,  $0c60,  $1c41,
  620.     $edae,  $fd8f,  $cdec,  $ddcd,  $ad2a,  $bd0b,  $8d68,  $9d49,
  621.     $7e97,  $6eb6,  $5ed5,  $4ef4,  $3e13,  $2e32,  $1e51,  $0e70,
  622.     $ff9f,  $efbe,  $dfdd,  $cffc,  $bf1b,  $af3a,  $9f59,  $8f78,
  623.     $9188,  $81a9,  $b1ca,  $a1eb,  $d10c,  $c12d,  $f14e,  $e16f,
  624.     $1080,  $00a1,  $30c2,  $20e3,  $5004,  $4025,  $7046,  $6067,
  625.     $83b9,  $9398,  $a3fb,  $b3da,  $c33d,  $d31c,  $e37f,  $f35e,
  626.     $02b1,  $1290,  $22f3,  $32d2,  $4235,  $5214,  $6277,  $7256,
  627.     $b5ea,  $a5cb,  $95a8,  $8589,  $f56e,  $e54f,  $d52c,  $c50d,
  628.     $34e2,  $24c3,  $14a0,  $0481,  $7466,  $6447,  $5424,  $4405,
  629.     $a7db,  $b7fa,  $8799,  $97b8,  $e75f,  $f77e,  $c71d,  $d73c,
  630.     $26d3,  $36f2,  $0691,  $16b0,  $6657,  $7676,  $4615,  $5634,
  631.     $d94c,  $c96d,  $f90e,  $e92f,  $99c8,  $89e9,  $b98a,  $a9ab,
  632.     $5844,  $4865,  $7806,  $6827,  $18c0,  $08e1,  $3882,  $28a3,
  633.     $cb7d,  $db5c,  $eb3f,  $fb1e,  $8bf9,  $9bd8,  $abbb,  $bb9a,
  634.     $4a75,  $5a54,  $6a37,  $7a16,  $0af1,  $1ad0,  $2ab3,  $3a92,
  635.     $fd2e,  $ed0f,  $dd6c,  $cd4d,  $bdaa,  $ad8b,  $9de8,  $8dc9,
  636.     $7c26,  $6c07,  $5c64,  $4c45,  $3ca2,  $2c83,  $1ce0,  $0cc1,
  637.     $ef1f,  $ff3e,  $cf5d,  $df7c,  $af9b,  $bfba,  $8fd9,  $9ff8,
  638.     $6e17,  $7e36,  $4e55,  $5e74,  $2e93,  $3eb2,  $0ed1,  $1ef0
  639. );
  640.  
  641. FUNCTION UpdCrc(cp: BYTE; crc: WORD): WORD;
  642. BEGIN { UpdCrc }
  643.    UpdCrc := crctab[((crc SHR 8) AND 255)] XOR (crc SHL 8) XOR cp
  644. END;
  645.  
  646. CONST crc_32_tab: ARRAY[0..255] OF LONGINT = (
  647. $00000000, $77073096, $ee0e612c, $990951ba, $076dc419, $706af48f, $e963a535, $9e6495a3,
  648. $0edb8832, $79dcb8a4, $e0d5e91e, $97d2d988, $09b64c2b, $7eb17cbd, $e7b82d07, $90bf1d91,
  649. $1db71064, $6ab020f2, $f3b97148, $84be41de, $1adad47d, $6ddde4eb, $f4d4b551, $83d385c7,
  650. $136c9856, $646ba8c0, $fd62f97a, $8a65c9ec, $14015c4f, $63066cd9, $fa0f3d63, $8d080df5,
  651. $3b6e20c8, $4c69105e, $d56041e4, $a2677172, $3c03e4d1, $4b04d447, $d20d85fd, $a50ab56b,
  652. $35b5a8fa, $42b2986c, $dbbbc9d6, $acbcf940, $32d86ce3, $45df5c75, $dcd60dcf, $abd13d59,
  653. $26d930ac, $51de003a, $c8d75180, $bfd06116, $21b4f4b5, $56b3c423, $cfba9599, $b8bda50f,
  654. $2802b89e, $5f058808, $c60cd9b2, $b10be924, $2f6f7c87, $58684c11, $c1611dab, $b6662d3d,
  655. $76dc4190, $01db7106, $98d220bc, $efd5102a, $71b18589, $06b6b51f, $9fbfe4a5, $e8b8d433,
  656. $7807c9a2, $0f00f934, $9609a88e, $e10e9818, $7f6a0dbb, $086d3d2d, $91646c97, $e6635c01,
  657. $6b6b51f4, $1c6c6162, $856530d8, $f262004e, $6c0695ed, $1b01a57b, $8208f4c1, $f50fc457,
  658. $65b0d9c6, $12b7e950, $8bbeb8ea, $fcb9887c, $62dd1ddf, $15da2d49, $8cd37cf3, $fbd44c65,
  659. $4db26158, $3ab551ce, $a3bc0074, $d4bb30e2, $4adfa541, $3dd895d7, $a4d1c46d, $d3d6f4fb,
  660. $4369e96a, $346ed9fc, $ad678846, $da60b8d0, $44042d73, $33031de5, $aa0a4c5f, $dd0d7cc9,
  661. $5005713c, $270241aa, $be0b1010, $c90c2086, $5768b525, $206f85b3, $b966d409, $ce61e49f,
  662. $5edef90e, $29d9c998, $b0d09822, $c7d7a8b4, $59b33d17, $2eb40d81, $b7bd5c3b, $c0ba6cad,
  663. $edb88320, $9abfb3b6, $03b6e20c, $74b1d29a, $ead54739, $9dd277af, $04db2615, $73dc1683,
  664. $e3630b12, $94643b84, $0d6d6a3e, $7a6a5aa8, $e40ecf0b, $9309ff9d, $0a00ae27, $7d079eb1,
  665. $f00f9344, $8708a3d2, $1e01f268, $6906c2fe, $f762575d, $806567cb, $196c3671, $6e6b06e7,
  666. $fed41b76, $89d32be0, $10da7a5a, $67dd4acc, $f9b9df6f, $8ebeeff9, $17b7be43, $60b08ed5,
  667. $d6d6a3e8, $a1d1937e, $38d8c2c4, $4fdff252, $d1bb67f1, $a6bc5767, $3fb506dd, $48b2364b,
  668. $d80d2bda, $af0a1b4c, $36034af6, $41047a60, $df60efc3, $a867df55, $316e8eef, $4669be79,
  669. $cb61b38c, $bc66831a, $256fd2a0, $5268e236, $cc0c7795, $bb0b4703, $220216b9, $5505262f,
  670. $c5ba3bbe, $b2bd0b28, $2bb45a92, $5cb36a04, $c2d7ffa7, $b5d0cf31, $2cd99e8b, $5bdeae1d,
  671. $9b64c2b0, $ec63f226, $756aa39c, $026d930a, $9c0906a9, $eb0e363f, $72076785, $05005713,
  672. $95bf4a82, $e2b87a14, $7bb12bae, $0cb61b38, $92d28e9b, $e5d5be0d, $7cdcefb7, $0bdbdf21,
  673. $86d3d2d4, $f1d4e242, $68ddb3f8, $1fda836e, $81be16cd, $f6b9265b, $6fb077e1, $18b74777,
  674. $88085ae6, $ff0f6a70, $66063bca, $11010b5c, $8f659eff, $f862ae69, $616bffd3, $166ccf45,
  675. $a00ae278, $d70dd2ee, $4e048354, $3903b3c2, $a7672661, $d06016f7, $4969474d, $3e6e77db,
  676. $aed16a4a, $d9d65adc, $40df0b66, $37d83bf0, $a9bcae53, $debb9ec5, $47b2cf7f, $30b5ffe9,
  677. $bdbdf21c, $cabac28a, $53b39330, $24b4a3a6, $bad03605, $cdd70693, $54de5729, $23d967bf,
  678. $b3667a2e, $c4614ab8, $5d681b02, $2a6f2b94, $b40bbe37, $c30c8ea1, $5a05df1b, $2d02ef8d
  679. );
  680.  
  681. FUNCTION UpdC32(octet: BYTE; crc: LONGINT) : LONGINT;
  682. BEGIN { UpdC32 }
  683.    UpdC32 := crc_32_tab[BYTE(crc XOR LONGINT(octet))] XOR ((crc SHR 8) AND $00FFFFFF)
  684. END;
  685.  
  686. Procedure LongHash (s: string; var r: pwtype);
  687.   { return modified 3-byte checksum }
  688. var i,j: integer;
  689.  Begin
  690.   for i:=1 to 3 do r[i]:=0;
  691.   j:=1;
  692.   for i:=1 to length(s) do
  693.     begin
  694.     r[j]:=r[j]+ord(s[i]);
  695.     if (r[j] mod 2)=0 then
  696.       begin
  697.       j:=j+1;
  698.       if (j=4) then j:=1;
  699.       end;
  700.     end;
  701.  end;
  702.  
  703.  
  704.  
  705. function numtowords(n:word):string;
  706.  const Eng: Array[0..9] of string[6] = ('Zero ','One ','Two ','Three ',
  707.                                         'Four ','Five ','Six ','Seven ',
  708.                                         'Eight ','Nine ');
  709.  var ts:string;
  710.      ns:string;
  711.      i :byte;
  712.      cn:byte;
  713.      c :integer;
  714.  begin
  715.  str(n,ns);
  716.  ts:='';
  717.  
  718.  for i:=1 to length(ns) do
  719.    begin
  720.    val(ns[i],cn,c);
  721.    ts:=ts+eng[cn];
  722.    end;
  723.  
  724.  numtowords:=rtrim(ts);
  725.  end;
  726.  
  727.  
  728. function ShortPath(s:string):string;
  729.  var t,u:string;
  730.  
  731.  function lastslash:byte;
  732.   var a:integer;
  733.   begin
  734.   u:=s;
  735.   for a:=length(u) downto 1 do
  736.    begin
  737.    if u[a]='\' then begin lastslash:=a; exit end;
  738.    end;
  739.   end;
  740.  var a:integer;
  741.  begin
  742.  if length(s)>30 then
  743.   begin
  744.   a:=lastslash;
  745.   t:=copy(s,1,pos('\',s))+'∙∙∙'+copy(s,a,length(s));
  746.   shortpath:=t;
  747.   end
  748.  else shortpath:=s;
  749.  end;
  750.  
  751.  
  752. function SplitFilePath(s:string):string;
  753.     var
  754.      D: DirStr;
  755.      N: NameStr;
  756.      E: ExtStr;
  757. begin
  758. fsplit(s,d,n,e);
  759. splitfilepath:=d;
  760. end;
  761.  
  762. function splitFileExt (s:string):string;
  763.     var
  764.      D: DirStr;
  765.      N: NameStr;
  766.      E: ExtStr;begin
  767. fsplit(s,d,n,e);
  768. splitfileext:=e;
  769. end;
  770.  
  771. function splitFileName(s:string):string;
  772.     var
  773.      D: DirStr;
  774.      N: NameStr;
  775.      E: ExtStr;begin
  776. fsplit(s,d,n,e);
  777. splitfilename:=n;
  778. end;
  779.  
  780. Procedure KillFileSpec(p:string);
  781.  var s:searchrec;
  782.      f:file;
  783.  begin
  784.  FindFirst(p,anyfile XOR directory,s);
  785.  While DosError=0 do
  786.   begin
  787.   assign(f,splitfilepath(p)+s.name);
  788.   erase(f);
  789.   FindNext(s);
  790.   end;
  791.  end;
  792.  
  793. procedure killallindir(p:string);
  794.  var s:searchrec;
  795.      f:file;
  796.  begin
  797.  FindFirst(p+'\*.*',anyfile XOR directory,s);
  798.  While DosError=0 do
  799.   begin
  800.   assign(f,p+'\'+s.name);
  801.   erase(f);
  802.   FindNext(s);
  803.   end;
  804.  end;
  805.  
  806.  
  807. Procedure PruneDir(p:string);
  808.  
  809.  var s:searchrec;
  810.  begin
  811.  if (p[1]=char('.')) and (p[2]=char('\')) then delete(p,1,2);
  812.  killallindir(p);
  813.  
  814.  FindFirst(p+'\*.*',directory,s);
  815.  While DosError=0 do
  816.   begin
  817.   if not ((s.name='.') or (s.name='..')) then
  818.     begin
  819.     killallindir(p+'\'+s.name);
  820.  
  821.     prunedir(p+'\'+s.name);
  822.  
  823.     {$I-}
  824.     rmdir(fexpand(p+'\'+s.name));
  825.     {$I+}
  826.     end;
  827.   FindNext(s);
  828.   end;
  829.  
  830.  {$I-}
  831.  rmdir(p);
  832.  {$I+}
  833.  end;
  834.  
  835.  
  836. function nowsecondssincemidnight: longint;
  837.  var h,m,s: word;
  838.  begin
  839.  curtime(h,m,s);
  840.  nowsecondssincemidnight:=secondssincemidnight(h,m,s);
  841.  end;
  842.  
  843. function nowmins: word;
  844.  var h,m,s: word;
  845.  begin
  846.  curtime(h,m,s);
  847.  nowmins:=h*60+m;
  848.  end;
  849.  
  850.  
  851. (*
  852. function LineWrapInput(var s:string):boolean;
  853.   var t:char;
  854.       i:byte;
  855.  
  856.   begin
  857.   s:='';
  858.   repeat until keypressed;
  859.   t:=readkey;
  860.   case t of
  861.     {KEY} #32..#126:
  862.     { BS} #8: if ord(s[0])>0 then
  863.                 begin
  864.                 s[0]:=chr(ord(s[0])-1);
  865.                 case ansi of
  866.                   true : begin
  867.                          gotoxy(wherex-1),wherey);
  868.                          write(' ');
  869.                          gotoxy(wherex-1,wherey);
  870.                          end;
  871.                   false: begin
  872.                          pr(#8+' '+#8);
  873.                          end;
  874.                   end;
  875.                 end;
  876.     end;
  877.   end;
  878. *)
  879.  
  880. function DtTmStamp: string;
  881.  var m,d,y,dw: word;
  882.      sm,sd: string[2];
  883.      sy:string[4];
  884.  
  885.      ts:string;
  886.      i:byte;
  887.  begin
  888.  getdate(y,m,d,dw);
  889.  
  890.  str(m:2,sm);
  891.  str(d:2,sd);
  892.  str(y:4,sy);
  893.  
  894.  sy:=copy(sy,3,2);
  895.  
  896.  ts:=concat(sy,'-',sm,'-',sd);
  897.  
  898.  for i:=1 to ord(ts[0]) do if ts[i]=' ' then ts[i]:='0';
  899.  
  900.  ts:=ts+' '+curtimestr;
  901.  
  902.  DtTmStamp:=ts;
  903.  
  904.  end;
  905.  
  906.  
  907. (*
  908. Function Carrier_On:boolean;          {TRUE if carrier present}
  909.      var a:word;
  910.      begin
  911.  
  912.      case PortNum of
  913.        1: A := $3F8;
  914.        2: A := $2F8;
  915.        3: A := $3E8;
  916.        4: A := $2E8;
  917.        end;
  918.  
  919.      Carrier_On:=odd ( Port[ A + $06 ] shr 7 )
  920.  
  921.      end;
  922. *)
  923.  
  924. function ToStr(s: longint): string;
  925.   var a: string;
  926.   begin
  927.   str(S,A);
  928.   ToStr:=A;
  929.   end;
  930.  
  931. function ToStr2(s: longint;b:byte): string;
  932.   var a: string;
  933.   begin
  934.   str(S:b,A);
  935.   if a[1]=' ' then a[1]:='0';
  936.   ToStr2:=A;
  937.   end;
  938.  
  939. function ToInt(s: string): word;
  940.   var a: word;
  941.       c:integer;
  942.  
  943.   begin
  944.   val(S,A,c);
  945.   ToInt:=a;
  946.   end;
  947.  
  948. function Tolong(s: string): longint;
  949.   var a:longint;
  950.       c:integer;
  951.  
  952.   begin
  953.   val(S,A,c);
  954.   Tolong:=a;
  955.   end;
  956.  
  957.  
  958.  
  959.  
  960. function ToStrb(var s: byte): string;
  961.   var a: string;
  962.   begin
  963.   str(S,A);
  964.   ToStrb:=A;
  965.   end;
  966.  
  967. function SecondsSinceMidnight(h,m,s:word):longint;
  968.   begin
  969.   SecondsSinceMidnight := (longint(h)*3600)+(longint(m)*60)+longint(s)
  970.   end;
  971.  
  972. function CurTimeStr: string;
  973.  Var Hour,Min,Sec,Sec100:word;
  974.      HourS,MinS,SecS,Sec100s:string[2];
  975.      i:byte;
  976.      t:string;
  977.  begin
  978.  GetTime(Hour,Min,Sec,Sec100);
  979.  
  980.  Str(Hour:2,HourS);
  981.  Str(Min:2,MinS);
  982.  Str(Sec:2,Secs);
  983.  
  984.  t:=concat(HourS,':',MinS,':',SecS);
  985.  for i:=1 to ord(t[0]) do
  986.   if t[i]=' ' then t[i]:='0';
  987.  CurTimeStr:=t;
  988.  end;
  989.  
  990. procedure CurTime(var h:word; var m: word;var s:word);
  991.  Var Hour,Min,Sec,Sec100:word;
  992.  begin
  993.  GetTime(Hour,Min,Sec,Sec100);
  994.  h:=hour;
  995.  m:=min;
  996.  s:=sec;
  997.  end;
  998.  
  999. function ltrim(s:string):string;
  1000.   begin
  1001.   if s='' then begin ltrim:=''; exit end;
  1002.   repeat
  1003.     begin
  1004.     if s[1]=' ' then delete(s,1,1);
  1005.     end;
  1006.   until s[1]<>' ';
  1007.   ltrim:=s;
  1008.   end;
  1009.  
  1010. Procedure CursorOff;
  1011.   var regs:registers;
  1012.   Begin
  1013.   Regs.Ax := $0100;
  1014.   Regs.Cx := $2807;
  1015.   Intr($10,Regs);
  1016.   End;
  1017.  
  1018. Procedure CursorOn;
  1019.   var regs:registers;
  1020.   Begin
  1021.   Regs.Ax := $0100;
  1022.   If LastMode = Mono Then
  1023.     Regs.Cx := $090A
  1024.   Else
  1025.     Regs.Cx := $0607;
  1026.   Intr($10,Regs);
  1027.   End;
  1028.  
  1029. procedure beep(hz,ms:word);
  1030.  begin
  1031.  sound(hz);
  1032.  delay(ms);
  1033.  nosound;
  1034.  end;
  1035.  
  1036. function rtrim(s:string):string;
  1037.   var a: byte;d:boolean;
  1038.   begin
  1039.   if s='' then begin rtrim:=''; exit end;
  1040.  
  1041.   d:=false;
  1042.   a:= ord(s[0]);
  1043.   repeat
  1044.    if s[a]=#32 then
  1045.     begin
  1046.     s[0] := chr(ord(s[0])-1);
  1047.     dec(a);
  1048.     end
  1049.   else d:=true;
  1050.   until d;
  1051.   rtrim:=s;
  1052.   end;
  1053.  
  1054. {
  1055. Procedure CursorOff;
  1056. Begin
  1057.   Inline($50/$51/$B4/$01/$B5/$FF/$B1/$0C/$CD/$10/$59/$58);
  1058. End;
  1059.  
  1060.  
  1061.  
  1062. Procedure CursorOn;
  1063. Begin
  1064.   Inline($50/$51/$B4/$01/$B5/$0C/$B1/$0D/$CD/$10/$59/$58);
  1065. End;
  1066. }
  1067.  
  1068. function compare(s1,s2:string):byte;
  1069.  begin
  1070.  s1:=upcasestr(s1);
  1071.  s2:=upcasestr(s2);
  1072.  
  1073.  if s1 = s2 then compare:=0;
  1074.  if s1 < s2 then compare:=2;
  1075.  if s1 > s2 then compare:=1;
  1076.  
  1077.  end;
  1078.  
  1079. function ExistFile(s:string;flags:word):boolean;
  1080.   var re:searchrec;
  1081.   begin
  1082.   FindFirst(s,flags,re);
  1083.   ExistFile := not((DosError=18) or (DosError=2) or (DosError=3));
  1084.   end;
  1085.  
  1086. function UpcaseStr(s:string):string;
  1087.   var a:byte;
  1088.   begin
  1089.   for a:=1 to ord(s[0]) do s[a] := upcase(s[a]);
  1090.   UpCaseStr := s;
  1091.   end;
  1092.  
  1093. function LowcaseStr(s:string):string;
  1094.   var a:byte;
  1095.   begin
  1096.   for a:=1 to ord(s[0]) do s[a] := lowcase(s[a]);
  1097.   lowCaseStr := s;
  1098.   end;
  1099.  
  1100. Function LTab(n: integer;m:integer):string;
  1101.   var a: string;
  1102.       b: integer;
  1103.   begin
  1104.   a := '';
  1105.   for b := n+1 to m do a:=a+' ';
  1106.   Ltab := a;
  1107.   end;
  1108.  
  1109. function  Ltabc(n,m:integer;c:char):string;
  1110.   var a: string;
  1111.       b: integer;
  1112.   begin
  1113.   a := '';
  1114.   for b := n+1 to m do a:=a+c;
  1115.   Ltabc := a;
  1116.   end;
  1117.  
  1118.  
  1119. function Key:char;
  1120.    begin
  1121.    Key := ReadKey;
  1122.    end;
  1123.  
  1124. procedure ClearScreen;
  1125.    begin
  1126.    if ANSI then ClrScr;
  1127.    end;
  1128.  
  1129.  
  1130. function CaseStr(s: string): string;
  1131.    var i: byte;
  1132.  
  1133.    begin
  1134.    s[1] := upcase(s[1]);
  1135.    for i := 2 to ord(s[0]) do
  1136.        begin
  1137.        case ord(s[i-1]) of
  1138.  
  1139.         32..46,58..64,91..96,132..126
  1140.           :  s[i] := upcase(s[i]);
  1141.         else s[i] := lowcase(s[i]);
  1142.         end;
  1143.        end;
  1144.    CaseStr := s;
  1145.    end;
  1146.  
  1147. function lowcase(ch: char): char;
  1148.   begin
  1149.   ch := upcase(Ch);
  1150.   case ord(ch) of
  1151.   65..90: Lowcase := chr(ord(ch)+32);
  1152.   else Lowcase := Ch;
  1153.   end;
  1154.   end;
  1155.  
  1156. procedure PR(t: string);
  1157.    begin
  1158.    if ANSI then write(t) else Write(output, t);
  1159.    end;
  1160.  
  1161. procedure Newline;
  1162.    begin
  1163.    if ANSI then writeln else write(output, #13,#10);
  1164.    end;
  1165.  
  1166. procedure ColorFG(c: byte);
  1167.     begin
  1168.     if ANSI then textcolor(c);
  1169.     end;
  1170.  
  1171. procedure ColorBG(c: byte);
  1172.     begin
  1173.     if ANSI then textbackground(c);
  1174.     end;
  1175.  
  1176. procedure PhoneEditor(var answerformain: string; prestring: string;fgc,bgc:byte);
  1177.     var
  1178.  tempkey      : char;
  1179.  stringtempkey: string[1];
  1180.   baseX       : byte;
  1181.   answer      : string[10];
  1182.   done        : boolean;
  1183.   i           : byte;
  1184.     begin
  1185.     done := false;
  1186.     baseX := whereX;
  1187.     answer := '';
  1188.     {
  1189.     if length(prestring) <> 0 then
  1190.       begin
  1191.       answer := prestring;
  1192.       for i:=1 to (10 - length(prestring)) do answer := answer + #32;
  1193.       ord(answer[0]) := length(prestring);
  1194.       end;
  1195.     }
  1196.     colorFG(fgc);
  1197.     colorBG(bgc);
  1198.     if ANSI then begin PR(' (   )    -     '); gotoXY(baseX+2, wherey); end
  1199.     else PR(' (');
  1200.     repeat
  1201.     tempkey := readkey;
  1202.     case tempkey of
  1203.        '0'..'9':if ord(answer[0]) < 10 then
  1204.                  begin
  1205.                    answer := answer + tempkey;
  1206.                    case ord(answer[0]) of
  1207.                      1,2,4,5,7,8,9,10:PR(tempkey);
  1208.                      3:
  1209.                        begin
  1210.                        if ANSI then begin pr(tempkey);gotoXY(basex+7, whereY) end
  1211.                        else PR(tempkey+') ');
  1212.                        end;
  1213.                      6:
  1214.                        begin
  1215.                        if ANSI then begin pr(tempkey);gotoXY(baseX+11, wherey) end
  1216.                        else PR(tempkey+'-');
  1217.                        end;
  1218.                    end;
  1219.                  end;
  1220.  
  1221.        #8: if ord(answer[0]) > 0 then
  1222.           begin
  1223.           delete(answer,ord(answer[0]),1);
  1224.           {dec(ord(answer[0]));}
  1225.           {answer := copy(answer, 1, ord(answer[0]));}
  1226.           case ord(answer[0]) of
  1227.                0,1,3,4,6,7,8,9,10: if ANSI then begin
  1228.                                                gotoXY(whereX-1, wherey);
  1229.                                                PR(' ');
  1230.                                                gotoXY(whereX-1, wherey);
  1231.                                                end
  1232.                                   else
  1233.                                                begin
  1234.                                                PR(#8+#32+#8);
  1235.                                                end;
  1236.  
  1237.                2: if ANSI then
  1238.                       begin
  1239.                       gotoXY(wherex-3, whereY);
  1240.                       PR(' ');
  1241.                       gotoXY(wherex-1, whereY);
  1242.                       end
  1243.                    else
  1244.                        begin
  1245.                        PR(#8+#8+#8+#32+#8);
  1246.                        end;
  1247.  
  1248.                5: if ANSI then
  1249.                       begin
  1250.                       gotoXY(whereX-2, wherey);
  1251.                       PR(' ');
  1252.                       gotoXY(wherex-1, whereY);
  1253.                       end
  1254.                   else
  1255.                       begin
  1256.                       PR(#8+#8+#32+#8);
  1257.                       end;
  1258.                end;
  1259.           end;
  1260.        #13:done := true;
  1261.  
  1262.        end;
  1263.     until done;
  1264.     colorBG(black);
  1265.     answerformain := answer;
  1266.     end;
  1267.  
  1268. procedure Editor(maxlen: byte; var answerformain: string; prestring: string;fgc,bgc:byte);
  1269.    var
  1270.        tempkey : char;
  1271.        done    : boolean;
  1272.        index   : byte;
  1273.        answer  : string;
  1274.        baseX   : byte;
  1275.        i       : byte;
  1276.      insertmode: boolean;
  1277.   stringtempkey: string[1];
  1278.  
  1279.    begin
  1280.    baseX := whereX;
  1281.    done := false;
  1282.  
  1283.    insertmode:=useinsert;
  1284.    if not(ansi) then useinsert:=false;
  1285.  
  1286.    index := 0;
  1287.    answer := '';
  1288.    if length(prestring) <> 0 then
  1289.       begin
  1290.       answer := prestring;
  1291.       index := length(prestring);
  1292.       end;
  1293.  
  1294.    if (ANSI and insertmode) then
  1295.      begin
  1296.      gotoXY(baseX+maxlen+2, whereY);
  1297.      ColorFG(lightred);ColorBG(black);
  1298.      PR('i');
  1299.      gotoxy(basex, wherey);
  1300.      end;
  1301.  
  1302.    ColorFG(fgc);
  1303.    ColorBG(bgc);
  1304.  
  1305.  
  1306.    PR(' '+Prestring);
  1307.  
  1308.    if ANSI then
  1309.      begin
  1310.      for i:=length(prestring)+1 to maxlen+1 do PR(' ');
  1311.      gotoXY(basex+1+index,wherey);
  1312.      end;
  1313.  
  1314.    { functions ... backspace, right, left, overwrite mode for L, R }
  1315.    {               enter, delete                                   }
  1316.  
  1317.    repeat
  1318.       repeat
  1319.        If portcheck then if not carrierfunc then
  1320.          begin
  1321.          Exit;
  1322.          end;
  1323.       until keypressed;
  1324.  
  1325.       tempkey := readkey;
  1326.       case tempkey of
  1327.         #32,
  1328.  
  1329.              {'A'..'Z', 'a'..'z','0'..'9', ',' , '.':}
  1330.  
  1331.              ' '..'~':
  1332.  
  1333.              begin
  1334.               if ord(answer[0]) < maxlen then
  1335.                begin
  1336.                inc(index);
  1337.                if index <= maxlen then
  1338.                begin
  1339.                if CapsOn then
  1340.    {for upcase} if (answer[index-1] = #32) or (Answer[index-1] = #0) then
  1341.    {checking}     begin
  1342.                   tempkey := upcase(tempkey);
  1343.                   end
  1344.                 else tempkey := lowcase(tempkey);
  1345.  
  1346.                if insertmode and ansi then
  1347.                   begin
  1348.                   if ord(answer[0]) < maxlen then
  1349.                     begin
  1350.                     stringtempkey := tempkey;
  1351.                     insert(stringtempkey, answer, index);
  1352.                     if CapsOn then Answer := CaseStr(Answer);
  1353.                     if index <> ord(answer[0]) then
  1354.                      begin
  1355.                      gotoxy(baseX+1, wherey);
  1356.                      PR(answer);
  1357.                      gotoxy(baseX+index+1, wherey);
  1358.                      end
  1359.                     else pr(tempkey);
  1360.                     end;
  1361.                   end
  1362.                else
  1363.                   begin
  1364.                   if index < ord(answer[0])+1 then answer[index] := tempkey
  1365.                   else answer := answer + tempkey;
  1366.                   PR(tempkey)
  1367.                   end;
  1368.                end;
  1369.               end;
  1370.              end;
  1371.         #13:
  1372.              begin
  1373.              done := true;
  1374.              end;
  1375.         #8:
  1376.              begin
  1377.  
  1378.              if (index > 0)  then
  1379.               begin
  1380.               dec(index);
  1381.               delete(answer, Index+1, 1);
  1382.               if ANSI then
  1383.                   begin
  1384.  
  1385.                   gotoXY(BaseX+Index+1, whereY);
  1386.                   PR(copy(answer, index+1, ord(answer[0])-index)+' ');
  1387.                   gotoXY(BaseX+index+1, whereY);
  1388.  
  1389.                    end
  1390.               else PR(#8+' '+#8);
  1391.               end;
  1392.              end;
  1393.         #0:                         { test for extended characters }
  1394.              begin
  1395.              case readkey of        { poll for extended part }
  1396.                #75:                 { left arrow }
  1397.                    begin
  1398.                    if ANSI then
  1399.                     begin
  1400.                     if index >= 1 then
  1401.                      begin
  1402.                      dec(index);
  1403.                      gotoxy(whereX-1, wherey);
  1404.                      end;
  1405.                     end;
  1406.                    end;
  1407.                #77:                 { right arrow }
  1408.                   begin
  1409.                   if ANSI then
  1410.                    begin
  1411.                    if index < ord(answer[0]) then
  1412.                      begin
  1413.                      inc(index);
  1414.                      gotoxy(whereX+1, whereY);
  1415.                      end;
  1416.                    end;
  1417.                   end;
  1418.                #71:                 { home }
  1419.                   begin
  1420.                   if ANSI then
  1421.                      begin
  1422.                      index := 0;
  1423.                      gotoxy(baseX+1, wherey);
  1424.                      end;
  1425.                   end;
  1426.  
  1427.                #79: IF ANSI then
  1428.                   begin
  1429.                   index := ord(answer[0]);
  1430.                   gotoXY(BaseX+Ord(answer[0])+1, whereY);
  1431.  
  1432.                   end;
  1433.  
  1434.                #82:      { ins }
  1435.                 if useinsert then
  1436.                   begin
  1437.                   gotoXY(baseX+maxlen+2, whereY);
  1438.                   ColorFG(lightred);ColorBG(black);
  1439.                   if insertmode then begin insertmode := false; PR(' ') end
  1440.                   else begin insertmode := true; PR('i'); end;
  1441.                   GotoXY(BaseX+Index+1, whereY);
  1442.                   ColorFG(white);ColorBG(blue);
  1443.                   end;
  1444.  
  1445.                #83:         { del }
  1446.                   begin
  1447.                   if ANSI then
  1448.                     begin
  1449.                     delete(answer,index+1,1);
  1450.                     If CapsOn then Answer := CaseStr(Answer);
  1451.                     gotoXY(baseX+1, whereY);
  1452.                     for i:=1 to ord(answer[0]) do PR(Answer[i]);
  1453.                     PR(' ');
  1454.  
  1455.                     gotoxy(baseX+index+1, wherey);
  1456.                     end;
  1457.                   end;
  1458.  
  1459.                end;                           { end of 'case readkey of' }
  1460.              end;                             { end of '#0: begin' }
  1461.         end;                                  { end of 'case tempkey of' }
  1462.    until done;
  1463.  
  1464.    {answer[0] := chr(ord(answer[0]));}
  1465.    answerformain := answer;
  1466.    if ANSI then gotoXY(baseX+maxlen+2, wherey) else
  1467.      for i := index to maxlen+1 do PR(' ');
  1468.    colorBG(black);PR(' '+#8+' ');
  1469.    end;
  1470.  
  1471.  
  1472. procedure setup_output;
  1473.    begin
  1474.    if ANSI = false then
  1475.       begin
  1476.       assign(output, '');
  1477.       rewrite(output);
  1478.       end;
  1479.    end;
  1480.  
  1481.  
  1482. procedure showmc(ch: char);
  1483.     begin
  1484.     colorFG(blue);PR('[');colorFG(white);PR(CH);colorFG(blue);PR(']');
  1485.     colorFG(cyan);PR(' ');
  1486.     end;
  1487.  
  1488.  
  1489. procedure GetChoice(numofchoices:byte; Choices:string;fgc,bgc,oc:byte; var Reply: byte);
  1490.    { last char of choices must NOT be #32 }
  1491.  
  1492.    type
  1493.        datatype = record
  1494.          beginpos: byte;
  1495.          text    : string;
  1496.          end;
  1497.         choicetype = array[1..10] of datatype;
  1498.  
  1499.    var
  1500.       i      : byte;
  1501.       c      : choicetype;
  1502.       incr   : byte;
  1503.       done   : boolean;
  1504.       baseX  : byte;
  1505.       tempkey: char;
  1506.       last   : byte;
  1507.       curc   : byte;
  1508.       oldc   : byte;
  1509.  
  1510.    begin
  1511.    if ANSI then
  1512.     Begin
  1513.     baseX := whereX;
  1514.     done := false;
  1515.     choices := choices+' ';
  1516.     last := 1;
  1517.     incr := 0;
  1518.     for i := 1 to length(choices) do
  1519.         if choices[i] = ' ' then
  1520.            begin
  1521.            inc(incr);
  1522.            c[incr].beginpos := (incr+last-2) ;
  1523.            c[incr].text := ' '+copy(choices,last,i-last)+' ';
  1524.            last := i+1;
  1525.            end;
  1526.     textcolor(oc);
  1527.     for i := 1 to incr do
  1528.          begin
  1529.          write(c[i].text);
  1530.          end;
  1531.  
  1532.     OldC := 1;
  1533.     CurC := 1;
  1534.  
  1535.     Textcolor(fgc);
  1536.     textbackground(bgc);
  1537.     gotoXY(baseX+c[CurC].beginpos, whereY);
  1538.     write(c[CurC].text);
  1539.  
  1540.     repeat
  1541.        begin
  1542.       repeat
  1543.        if portcheck then
  1544.         if not carrierfunc then
  1545.          begin
  1546.          Exit;
  1547.          end;
  1548.       until keypressed;
  1549.  
  1550.  
  1551.        tempkey := readkey;
  1552.        case upcase(tempkey) of
  1553.           #0:
  1554.              case readkey of
  1555.                #77:
  1556.                    begin
  1557.                    inc(CurC);
  1558.                    if CurC = numofchoices+1 then CurC := 1;
  1559.                    end;
  1560.                 #75:
  1561.                    begin
  1562.                    dec(CurC);
  1563.                    if CurC = 0 then CurC := numofchoices;
  1564.                    end;
  1565.                end;
  1566.  
  1567.           #32:begin
  1568.               CurC := CurC +1;
  1569.               if CurC = numofchoices+1 then CurC := 1
  1570.               end;
  1571.  
  1572.           #13: done := true;
  1573.           else
  1574.                for i := 1 to numofchoices do
  1575.                    if upcase(tempkey) = c[i].text[2] then
  1576.                                       begin
  1577.                                       CurC := i;
  1578.                                       done := true;
  1579.                                       end;
  1580.  
  1581.           end;
  1582.        if OldC <> CurC then
  1583.          begin
  1584.          textcolor(oc);
  1585.          textbackground(black);
  1586.          gotoXY(baseX+c[oldc].beginpos, wherey);
  1587.          write(c[oldc].text);
  1588.  
  1589.          textbackground(bgc);
  1590.          textcolor(fgc);
  1591.          gotoXY(basex+c[curc].beginpos, wherey);
  1592.          write(c[curc].text);
  1593.          end;
  1594.  
  1595.        OldC := CurC
  1596.        end;
  1597.     until done;
  1598.  
  1599.     colorBG(black);PR(' '+#8+' ');
  1600.     Reply := CurC;
  1601.  
  1602.     end
  1603.  
  1604.    else
  1605.  
  1606.     begin
  1607.     incr := 0;
  1608.     last := 1;
  1609.     done := false;
  1610.     choices := Choices + ' ';
  1611.  
  1612.     for i := 1 to length(choices) do
  1613.      if choices[i] = ' ' then
  1614.         begin
  1615.         inc(incr);
  1616.         c[incr].text := copy(choices, last, i-last);
  1617.         {writeln(c[incr].text);}
  1618.         c[incr].text := '['+c[incr].text[1]+']'+copy(c[incr].text,2,ord(c[incr].text[0])-1)+' ';
  1619.         last := i+1;
  1620.         end;
  1621.     For i := 1 to numofchoices do PR(c[i].text);
  1622.     PR('-> ');
  1623.     repeat
  1624.         begin
  1625.         tempkey := upcase(readkey);
  1626.         for i := 1 to numofchoices do
  1627.             begin
  1628.             if tempkey = c[i].text[2] then begin done := true; Reply := i;end
  1629.             end;
  1630.         end;
  1631.     until done;
  1632.     PR(c[reply].text[2] + copy(c[reply].text,4,length(c[reply].text)-4));
  1633.     end;
  1634.    end;
  1635.  
  1636. procedure PrintScreen;
  1637.  begin
  1638.   InLine ($CD/$05)
  1639.  end;
  1640.  
  1641.  
  1642. begin   {initialize the global variables }
  1643.     ANSI := true;
  1644.     carrierfunc:=nil;
  1645.     useinsert := true;
  1646.     CapsOn := true;
  1647.     PortCheck := false;
  1648. end.
  1649.  
  1650.